package xyz.jangle.string;

public class StringMain6 {

	public static void main(String[] args) {
		
		
		System.out.println(test("abcabd"));

	}
	/**
	 * 最长子字符串（滑动窗口求解）
	 * @param str
	 * @return
	 */
	public static int test(String str) {
		char[] array = str.toCharArray();
		int left = 0;
		int result = 0;
		boolean[] has = new boolean[128];
		for (int right = 0; right < array.length; right++) {
			while(has[array[right]]) {
				has[array[left++]]=false;
			}
			has[array[right]]=true;
			result = Math.max(result, right-left+1);
		}
		return result;
	}

}
